//
//  TabBarController.m
//  PeiJue
//
//  Created by lxy on 2017/9/21.
//  Copyright © 2017年 lixiya. All rights reserved.
//

#import "TabBarController.h"
#import "NavigationController.h"

#import "PJTestViewController.h"
#import "ThreeViewController.h"


@interface TabBarController ()
@end

@implementation TabBarController

+ (void)initialize
{
    // 设置底部tabbar的主题样式
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
    
    [[UITabBarItem appearance] setTitleTextAttributes:
     [NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0],NSForegroundColorAttributeName, nil]forState:UIControlStateSelected];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self configureTabBar];
    
    // 添加所有的控制器
    [self addAllChildVcs];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Privates
- (void)configureTabBar {
    self.tabBar.shadowImage = [UIImage imageNamed:@"tabbartop-line"];
    
    if (ios8x) {
        [self.tabBar setBackgroundImage:[UIImage imageFromContextWithColor:[UIColor colorWithRed:238/255.0 green:240/255.0 blue:245/255.0 alpha:0.78]]];
        
        // blur效果
        UIVisualEffectView *visualEfView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
        visualEfView.frame = CGRectMake(0, -1, CGRectGetWidth(self.tabBar.frame), CGRectGetHeight(self.tabBar.frame)+1);
        visualEfView.alpha = 1.0;
        [self.tabBar insertSubview:visualEfView atIndex:0];
    }
}


- (void)addAllChildVcs {
    
    PJTestViewController * one = [[PJTestViewController alloc] init];
    [self addOneChildVc:one title:@"one" imageName:@"tabBar_essence_icon" selectedImageName:@"tabBar_essence_click_icon"];
    
    PJTestViewController * two = [[PJTestViewController alloc] init];
    [self addOneChildVc:two title:@"two" imageName:@"tabBar_essence_icon" selectedImageName:@"tabBar_essence_click_icon"];
    
    ThreeViewController * three = [[ThreeViewController alloc] init];
    [self addOneChildVc:three title:@"three" imageName:@"tabBar_essence_icon" selectedImageName:@"tabBar_essence_click_icon"];
}


- (void)addOneChildVc:(UIViewController *)childVc title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName {
    childVc.tabBarItem.title = title;
    
    UIImage * normalImg = [UIImage imageNamed:imageName];
    UIImage * selectImg = [UIImage imageNamed:selectedImageName];
    childVc.tabBarItem.image = [normalImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childVc.tabBarItem.selectedImage = [selectImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //设置不规则tabBarItem
    // [childVc.tabBarItem setImageInsets:UIEdgeInsetsMake(-20, 0, 20, 0)];
    
    //..使用我们自定义的导航栏
    NavigationController *nav = [[NavigationController alloc] initWithRootViewController:childVc];
    [self addChildViewController:nav];
}




@end

